package com.codejob.portal.web.action.company;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.codejob.portal.dao.utils.Page;
import com.codejob.portal.entity.company.Company;
import com.codejob.portal.services.impl.company.CompanyManager;
import com.codejob.portal.services.intf.BusinessExcption;
import com.codejob.portal.web.BaseModelAction;

@Namespace("/company")
public class CompanyAction extends BaseModelAction<Company> {
	private static final long serialVersionUID = 1973327595404902706L;
	private Company company;
	@Autowired
	private CompanyManager comManager;
	private Long id;
	
	private Page<Company> page=new Page<Company>(5);
	
	public String companyIndex(){
		//设置默认排序方式
		if (page!=null&&!page.isOrderBySetted()) {
			page.setOrderBy("look");
			page.setOrder(Page.DESC);
		}
		try {
			page=comManager.getCompanyPager(page);
		} catch (BusinessExcption e) {
			e.printStackTrace();
		}
		return "comIndex";
	}
	public String look(){
		
		return "lookCom";
	}
	public String prepareCreate(){
		if(!isLogin()){
			return "login";
		}
		return "createCom";
	}
	
	public String createCom(){
		if(!isLogin()){
			return "login";
		}
		try {
			comManager.create(company,this.getUserId());
		} catch (BusinessExcption e) {
			e.printStackTrace();
		}
		return "createSuccess";
	}

	@Override
	public Company getModel() {
		return company;
	}

	@Override
	public void prepare() throws Exception {
		if(id!=null&&id!=0){
			company=comManager.getById(id);
		}
		if(company==null){
			company=new Company();
		}
		
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public CompanyManager getComManager() {
		return comManager;
	}

	public void setComManager(CompanyManager comManager) {
		this.comManager = comManager;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Page<Company> getPage() {
		return page;
	}

	public void setPage(Page<Company> page) {
		this.page = page;
	}

}
